package cn.ryh.po;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @ClassName TestDiByAnnotation
 * @Description 用于测试通过注解注入
 * @Author RaoYH
 */
@Component
public class TestDiByAnnotation {
    @Value(value = "Spring")
    private String name;
    /**
     * 可以使用@Autowired和Resource
     */
    @Autowired
    private User user;

    private Integer[] arrary;

    private List<Integer> list;

    private Map<Integer,Integer> map;
    /**
     * 注解注入Arrary,系统运行时会将IOC容器中实例化好的所有user和其子类添加进来
     */
    @Autowired
    private User[] userArrary;
    /**
     * 注解注入List,系统运行时会将IOC容器中实例化好的所有user和其子类添加进来
     */
    @Autowired
    private List<User> userList;
    /**
     * 注解注入Map,系统运行时会将IOC容器中实例化好的所有user和其子类添加进来,其key为beanName
     */
    @Autowired
    private Map<String,User> userMap;

    @Override
    public String toString() {
        return "TestDiByAnnotation{" +
                "name='" + name + '\'' +
                ", user=" + user +
                ", arrary=" + Arrays.toString(arrary) +
                ", list=" + list +
                ", map=" + map +
                ", userArrary=" + Arrays.toString(userArrary) +
                ", userList=" + userList +
                ", userMap=" + userMap +
                '}';
    }
}
